package com.it00zyq.common.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author IT00ZYQ
 * @Date 2021/2/1 1:51
 **/
@Component
@EnableConfigurationProperties(WxAppProperties.class)
public class WxAppConfig {

    private final WxAppProperties properties;
    public WxAppConfig(WxAppProperties properties) {
        this.properties = properties;
    }

    public static WxMaService wxMaService;
    public static WxAppProperties wxOpenProperties;

    @PostConstruct
    public void init() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(properties.getAppId());
        config.setSecret(properties.getAppSecret());
        wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        System.out.println(properties.getAppId());
        System.out.println(properties.getAppSecret());
        wxOpenProperties = this.properties;
    }

    @Bean
    public WxMaService wxMpService() {
        return wxMaService;
    }


}
